/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
jQuery.noConflict();

var webjs = {
    tosbox: null,
    tostitle: "TOS",
    langcode: "no",
    key: "",
    uid: "",
    lightboxPaddingTop: 180,
    lightboxAutoAdjust: false,
    isHaveSingleChoice: false,
    langs: {
        today_question: "Dagens spørsmål, ",
        dot_december: ". desember",
        cancel: "Avbryt",
        close: "Lukk",
        thank_message: "<center>Takk for ditt svar<br/><br/>Alle vinnere vil bli kontaktet på E-post.</center>"
    },
    resizeLightbox: function(){
        jQuery(".lightface").css("top", webjs.lightboxPaddingTop);
    },
    onSubmitForm: function(f){
        //check validate first
        var isvalid = jQuery(f).valid();
        if(webjs.isHaveSingleChoice){
            if(!jQuery(".question_choice:checked").val()){
                jQuery(".question_error").css("display","block");
                isvalid = false;
            }
        }
        if(isvalid) {
            webjs.blockUIMessageBox("...");
            jQuery("#mainformhome").css("display", "none");
            jQuery.post("?action=submitdata", jQuery(f).serialize(), function(r){
                jQuery(".success-message").fadeIn();
                jQuery.unblockUI();
            });
        }
        return false;
    },
    hideSingleChoiceError:function(){
        jQuery(".question_error").css("display","none");
    },
    showTOSWindow: function() {
        var randString = Math.random();
        var objectURL = '?action=tos&key=' + webjs.key + "&uid=" + webjs.uid;
        if(webjs.tosbox == null) {
            webjs.tosbox = new LightFace.Request({
                url: objectURL,
                width: 420,
                draggable: false,
                resetOnScroll: webjs.lightboxAutoAdjust,
                zIndex: 999,
                onOpen:function(){
                    if(!webjs.lightboxAutoAdjust){
                        webjs.resizeLightbox();
                    }
                },
                onComplete:function(){
                    if(!webjs.lightboxAutoAdjust){
                        webjs.resizeLightbox();
                    } else {

                    }
                },
                buttons: [
                    {
                        title: webjs.langs.close,
                        event: function() {
                            this.close();
                        },
                        color: 'blue'
                    }
                ],
                request:{
                    evalScripts: true
                },
                title: webjs.tostitle
            }).open();
        } else {
            webjs.tosbox.open();
        }
        return void(0);
    },
    lockScreen: function(id) {
        var w = jQuery(document).width();
        var neww = (w/2) - (520/2) - 10;
        jQuery.blockUI({message: jQuery("#" + id),
            css: {
                top: "170px",
                width: "520px",
                left: neww + "px"
            }
        });
    },
    blockUIMessageBox: function(message) {
        jQuery.blockUI({message: message,
            css: {
            border: 'none',
            padding: '15px',
            backgroundColor: '#000',
            '-webkit-border-radius': '10px',
            '-moz-border-radius': '10px',
            opacity: .5,
            color: '#fff'
        }});
        jQuery('.blockOverlay').attr('title','Click to unblock').click(jQuery.unblockUI);
    },
    shareData: {

    },

    setFacebookShareData: function(shareData)
    {
        webjs.shareData = shareData;
    },

    share: function(){
        var shareData = webjs.shareData;
        FB.ui(
                {
                    method: 'feed',
                    picture: shareData.picture,
                    name: shareData.name,
                    caption: shareData.caption,
                    link:shareData.url,
                    description: shareData.description,
                    action_links: [
                        {text: shareData.actionText, href: shareData.url}
                    ]
                },
                function(response) {
                    if (response && response.post_id) {
                    } else {
                    }
                }
            );
    },
    sendRequestViaMultiFriendSelector: function(title, message) {
      FB.ui({method: 'apprequests',
            title: title,
            message: message
      }, function(response) {});
    }
};

